package com.yanqu.road.server.channelserver.cmd.activity.tonbing;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ChannelTonBingProto;
import com.yanqu.road.server.channelserver.manager.activity.tonbing.ChannelTonBingMgr;
import com.yanqu.road.server.channelserver.manager.activity.tonbing.activity.ChannelTonBingActivity;
import com.yanqu.road.server.channelserver.manager.user.ChannelUserMgr;
import com.yanqu.road.server.cmd.CrossChannelCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.protocol.ChannelProtocol;

@Cmd(code = ChannelProtocol.N_TON_BING_LOGIN, desc = "")
public class ChannelTonBingLoginCmd extends CrossChannelCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ChannelTonBingProto.ChannelTonBingLoginReqMsg reqMsg = ChannelTonBingProto.ChannelTonBingLoginReqMsg.parseFrom(packet.getBytes());

        ChannelTonBingActivity activity = ChannelTonBingMgr.getActivity(reqMsg.getActivityId());
        if(activity.loginByCmd(packet.getPlayerId(), reqMsg)){
            // 更新userBaseInfo
            UserBaseInfo userBaseInfo = PlayerBasePb.parseBaseUserInfo(reqMsg.getUserBaseInfo());
            ChannelUserMgr.updateUserBaseInfo(packet.getPlayerId(), userBaseInfo);
        }
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

    }

    @Override
    public void sendData() {

    }
}
